package clock;


import javax.swing.*;
import java.awt.event.*;

/**
 * @author yangsiguo
 * @date 2019/5/16
 * @desc TODO add description in here
 */
public class Dialog {

    static int mx;
    static int my;
    static int jfx;
    static int jfy;

    public static JFrame createDialog(){
        JFrame frame = new JFrame();
        frame.setUndecorated(true);
        frame.setBounds(0, 0,500 , 300);

//        jFrame.setBackground(new Color(r, g, b, int alph));

//        AWTUtilities.setWindowOpacity(frame,0.6f);
//        AWTUtilities.setWindowShape(frame,new Rectangle());

        JPanel pane = (JPanel) frame.getContentPane();

//        pane.addMouseMotionListener(new MouseMotionAdapter() {
//            public void mouseDragged(MouseEvent e) {
//                frame.setLocation(jfx+(e.getXOnScreen()-mx), jfy+(e.getYOnScreen()-my));
//            }
//        });
//        pane.addMouseListener(new MouseAdapter() {
//            public void mousePressed(MouseEvent e) {
//                mx=e.getXOnScreen();
//                my=e.getYOnScreen();
//                jfx=frame.getX();
//                jfy=frame.getY();
//            }
//        });
        frame.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {

            }

            @Override
            public void keyPressed(KeyEvent e) {
                if (KeyEvent.VK_ESCAPE == e.getKeyCode()){
                    System.out.println("exit");
                    System.exit(0);
                }else if(KeyEvent.VK_ENTER == e.getKeyCode()){
                    System.out.println("hide");
                    frame.setVisible(false);
                }
            }

            @Override
            public void keyReleased(KeyEvent e) {

            }
        });

//        JButton button = new JButton("dd");
//        pane.add(button);

//        frame.setContentPane(pane);

//        AWTUtilities.setWindowOpaque(frame, false);

        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);   //最大化
        frame.setAlwaysOnTop(true);         //总在最前面
        frame.setResizable(false);         //不能改变大小
        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
//        frame.setVisible(true);

        return frame;
    }

    public static void main(String[] args) {
        JFrame frame = createDialog();
        frame.setVisible(true);
    }
}
